﻿@page "/accination"
@using System.ComponentModel.DataAnnotations
@inject MessageService _message

<Card Bordered="true" Title=@("接种记录")>
    <Body>
        <Table TItem="AccinationDto" DataSource="@datas">

            <Column @bind-Field="@context.UserName"></Column>
            <Column @bind-Field="@context.VaccineName"></Column>
            <Column @bind-Field="@context.BookedTime"></Column>
            <Column @bind-Field="@context.CompletedTime"></Column>
            <ActionColumn Title="操作">



                <Space Size=@("middle")>
                    <Space>
                        @if (context.Status == 1)
                        {
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Edit" OnClick="()=>EditStatus(context)">接种</Button>
                            </SpaceItem>

                        }
                        else
                        {
                            <SpaceItem>
                                已接种
                            </SpaceItem>
                        }
                    </Space>
                </Space>

            </ActionColumn>
        </Table>
    </Body>
</Card>

@code {
    AccinationDto current = new();

    private async void EditStatus(AccinationDto dto)
    {
        current = dto;
        current.Status = 2;
        await _message.Success("接种成功！");
    }


    List<AccinationDto> datas = new List<AccinationDto>
                                                                 {
                    new()
                    {
                       Id=2,
                       UserName="张三",
                       BookedTime=DateTime.Now.AddDays(-1),
                       VaccineName="新型冠状病毒灭活疫苗2",
                       Status=1,
                       CompletedTime=DateTime.Now
                    },
                    new()
                    {
                       Id=2,
                       BookedTime=DateTime.Now.AddDays(-1),
                       UserName="李四",
                       VaccineName="新型冠状病毒灭活疫苗2",
                       Status=1,
                       CompletedTime=DateTime.Now
                    },
                                                                };

    public class AccinationDto
    {
        /// <summary>
        /// Id
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 预约接种时间
        /// </summary>
        [DisplayName("预约接种时间")]
        public DateTime BookedTime { get; set; }

        /// <summary>
        /// 预约接种用户名
        /// </summary>
        [DisplayName("预约接种用户")]
        public string? UserName { get; set; }

        /// <summary>
        /// 疫苗名称
        /// </summary>
        [DisplayName("疫苗名称")]
        public string? VaccineName { get; set; }

        /// <summary>
        /// 接种状态（1-待接种/2-已接种）
        /// </summary>
        public int Status { get; set; }

        /// <summary>
        /// 接种完成时间
        /// </summary>
        [DisplayName("接种完成时间")]
        public DateTime? CompletedTime { get; set; }
    }
}
